<template>
  <el-table :data="tableData" style="width: 100%">
    <el-table-column prop="id" label="序号" />
    <el-table-column prop="type" label="类型" />
    <el-table-column prop="title" label="标题" />
    <el-table-column prop="remoteAddr" label="IP地址" />
    <el-table-column prop="method" label="请求方式" />
    <el-table-column prop="userAgent" label="客户端" />
    <el-table-column prop="time" label="请求时间" />
    <el-table-column prop="crerteTime" label="创建时间" />
    <el-table-column label="操作">
      <template #default="scope">
        <div style="display: flex; align-items: center;color: blue;">
          <el-icon style="font-size: 15px;"><View /></el-icon>
          &nbsp;&nbsp;
          <el-text style="color: blue;" @click="LogUpdate(scope.row)">
            查看
          </el-text>
          &nbsp;&nbsp;&nbsp;
          <el-icon style="font-size: 15px;"><DeleteFilled /></el-icon>
          &nbsp;&nbsp;
          <el-text style="color: blue;" @click="LogDelete(scope.row.id)">
            删除
          </el-text>
        </div>
      </template>
    </el-table-column>
  </el-table>
  <!-- 分页 -->
  <div class="demo-pagination-block">
    <el-pagination
      v-model:current-page="form.pageNum"
      v-model:page-size="form.pageSize"
      :page-sizes="[5, 10, 15, 20]"
      :small="small"
      :disabled="disabled"
      :background="background"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
  <!--查看弹框-->
  <el-dialog v-model="dialogFormVisible" title="查看界面" width="500">
    <el-form :model="formData">
      <el-form-item label="序号">
        <el-input disabled v-model="formData.id" />
      </el-form-item>
      <el-form-item label="类型">
        <el-input v-model="formData.type" />
      </el-form-item>
      <el-form-item label="标题">
        <el-input v-model="formData.title" />
      </el-form-item>
      <el-form-item label="IP地址">
        <el-input v-model="formData.remoteAddr" />
      </el-form-item>
      <el-form-item label="客户端">
        <el-input v-model="formData.userAgent" />
      </el-form-item>
      <el-form-item label="请求方式">
        <el-input v-model="formData.method" />
      </el-form-item>
      <el-form-item label="请求时间">
        <el-input disabled v-model="formData.time" />
      </el-form-item>
      <el-form-item label="创建时间">
        <el-input disabled v-model="formData.crerteTime" />
      </el-form-item>
    </el-form>
  </el-dialog>
</template>
<script setup>
import { ref } from 'vue'
import request from '@/utils/request'
import { ElMessage } from 'element-plus'
const tableData = ref([])
// 分页 数据
const total = ref(10)
const small = ref(false)
const background = ref(false)
const disabled = ref(false)

const form = ref({
  pageNum: 1,
  pageSize: 5,
})
//分页方法
const handleCurrentChange = val => {
  form.value.pageNum = val
  LogList()
}

const handleSizeChange = val => {
  form.value.pageSize = val
  LogList()
}

function LogList() {
  request({
    url: '/service-product/tLog/list',
    method: 'get',
    params: form.value,
  }).then(res => {
    tableData.value = res.data.records
    total.value = res.data.total
  })
}
LogList()

const dialogFormVisible = ref(false)
const formData = ref({
  id: '',
  type: '',
  title: '',
  remoteAddr: '',
  userAgent: '',
  method: '',
  time: '',
  crerteTime: '',
})

function LogUpdate(row) {
  dialogFormVisible.value = true
  formData.value.id = row.id
  formData.value.type = row.type
  formData.value.title = row.title
  formData.value.remoteAddr = row.remoteAddr
  formData.value.userAgent = row.userAgent
  formData.value.method = row.method
  formData.value.time = row.time
  formData.value.crerteTime = row.crerteTime
}

function LogDelete(id) {
  var bo = confirm('确定删除吗？')
  if (bo) {
    request({
      url: '/service-product/tLog/delete',
      method: 'delete',
      params: {
        id: id,
      },
    }).then(res => {
      if (res.code === 200) {
        ElMessage.success(res.msg)
        LogList()
      } else {
        ElMessage.error(res.msg)
      }
    })
  } else {
    ElMessage.warning('你取消了删除')
  }
}
</script>
